﻿namespace BM.Tools.WebControls.MForm.Controls.Modifiers
{
    using System;
    using System.Xml.Schema;

    using BM.Tools.WebControls.MForm.Controls.Items;
    using BM.Tools.WebControls.MForm.Generator;

    /// <summary>
    /// </summary>
    public class NumberFormatterModifier : LeafModifier
    {
        /// <summary>
        /// </summary>
        /// <param name="offspringItem">
        /// The offspring item.
        /// </param>
        protected override void OnItemPreRender(LeafItem offspringItem, EventArgs args)
        {
            if (offspringItem.Mode.Equals(FormBuilderMode.Edit))
            {
                if (offspringItem.DataType != XmlTypeCode.Decimal && offspringItem.DataType != XmlTypeCode.Float)
                {
                    return;
                }

                if (offspringItem.Input == null)
                {
                    return;
                }

                offspringItem.Input.Attributes.Add(
                        "onchange", offspringItem.Input.Attributes["onchange"] + " NumberFormatter.toShow(this);");
                offspringItem.Input.Attributes.Add(
                        "onblur", offspringItem.Input.Attributes["onblur"] + " NumberFormatter.toShow(this);");
                offspringItem.Input.Attributes.Add(
                        "onFocus", offspringItem.Input.Attributes["onFocus"] + " NumberFormatter.toEdit(this);");
            }
        }
    }
}